package com.athuiju.fenxiaoback.entity;

import java.math.BigDecimal;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
import java.util.List;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
 * <p>
 * 
 * </p>
 *
 * @author athuiju
 * @since 2021-07-02
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="TbCart对象", description="")
public class TbCart implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    @ApiModelProperty(value = "商品的数量")
    private Integer countNum;

    @ApiModelProperty(value = "商品的类型数量")
    private Integer countType;

    @ApiModelProperty(value = "整个购物车的总价")
    private BigDecimal totalAmount;

    @ApiModelProperty(value = "会员id")
    private Long memberid;

    @ApiModelProperty(value = "购车项集合")
    @TableField(exist = false)
    private List<TbCartitem> items;

    /**
     * 减免的价格
     */
    //private BigDecimal reduce = new BigDecimal("0.00");


    public List<TbCartitem> getItems() {
        return items;
    }

    public void setItems(List<TbCartitem> items) {
        this.items = items;
    }

    /**
     * 计算商品的总量
     * @return
     */
    public Integer getCountNum() {
        int count = 0;
        if(this.items != null && this.items.size() > 0){
            for (TbCartitem item : this.items) {
                count += item.getCount();
            }
        }
        return count;
    }

    public Integer getCountType() {
        int count = 0;
        if(this.items != null && this.items.size() > 0){
            for (TbCartitem item : this.items) {
                count += 1;
            }
        }
        return count;
    }

    public BigDecimal getTotalAmount() {
        BigDecimal amount = new BigDecimal("0");
        if(this.items != null && this.items.size() > 0){
            for (TbCartitem item : this.items) {
                if(item.getCheck()){
                    BigDecimal totalPrice = item.getTotalPrice();
                    amount = amount.add(totalPrice);
                }
            }
        }
        return amount;
    }




}
